package com.younion.action.consumer.impl;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.younion.action.consumer.AbstractRequestConsumer;
import com.younion.action.interactive.mobile.ApiConstant;
import com.younion.action.interactive.mobile.ResultObject;
import com.younion.business.IRegisterUserService;
import com.younion.model.UserInfoResult;
import com.younion.util.HttpRequestUtils;
import com.younion.util.JsonUtils;
import com.younion.vo.RegioninfoVO;
import com.younion.vo.RegisterUserVO;

public class UserInfoGetConsumer extends AbstractRequestConsumer {
	private IRegisterUserService registerUserService = null;

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return getUserInfo(request, response);
	}

	public String getUserInfo(HttpServletRequest request,
			HttpServletResponse response) {
		UserInfoResult userInfoResult = new UserInfoResult();
		RegisterUserVO registerUserVO = null;
		String userToken = request.getParameter("user_token");
		Map paramMap = new HashMap();
		ResultObject resultObject = new ResultObject();
		try {
			paramMap.put("userToken", userToken);
			registerUserVO = registerUserService.getVOByMap(paramMap);
			if (registerUserVO != null) {
				userInfoResult.setId(registerUserVO.getId().toString());
				userInfoResult.setUserName(registerUserVO.getUserName()!=null?registerUserVO.getUserName():"");
				userInfoResult.setPhone(registerUserVO.getPhone()!=null?registerUserVO.getPhone():"");
				userInfoResult.setEmail(registerUserVO.getEmail()!=null?registerUserVO.getEmail():"");
				userInfoResult.setProvince(registerUserVO.getProvince()!=null?registerUserVO.getProvince():new RegioninfoVO());
				userInfoResult.setCity(registerUserVO.getCity()!=null?registerUserVO.getCity():new RegioninfoVO());
				userInfoResult.setDistrict(registerUserVO.getDistrict()!=null?registerUserVO.getDistrict():new RegioninfoVO());
				resultObject.setStatus(ApiConstant.SUCCESS_STATUS);
			} else {
				resultObject.setStatus(ApiConstant.FALSE_STATUS);
				resultObject.setMsg(ApiConstant.REGIS_ERRO_USER);
			}
		} catch (Exception e) {
			resultObject.setStatus(ApiConstant.FALSE_STATUS);
			resultObject.setMsg(ApiConstant.PUBLIC_EXCEPTION);
			e.printStackTrace();
		}
		resultObject.setResult(userInfoResult);
		HttpRequestUtils.printContent(JsonUtils.parseObj2Json(resultObject),
				response);
		return null;
	}

	public void setRegisterUserService(IRegisterUserService registerUserService) {
		this.registerUserService = registerUserService;
	}

}
